<?php

abstract class Auth_Acl_Storage_Abstract {

	protected $_cacheFrontendOptions = array(
	   'lifetime' => 7200, // cache lifetime of 2 hours
	   'automatic_serialization' => true
	);

	protected $_cacheBackendOptions = array(
    	'cache_dir' => '/tmp',
	'cache_file_umask' => 0777
	);

	protected $_cacheIdentify = __CLASS__;
	
	protected $_cache = null;

	function useCache($flag) {
		if ($flag) $this->_cache = Zend_Cache::factory('core','file', 
			$this->_cacheFrontendOptions, $this->_cacheBackendOptions);
		 
		return $this;
	}

	abstract protected function _gen() ;

	function generate() {

		if ($this->_cache instanceof Zend_Cache_Core) {
			
			if (!$result = $this->_cache->load(strtolower($this->_cacheIdentify))) {
				$result = $this->_gen();
				$this->_cache->save($result, strtolower($this->_cacheIdentify));
			}

		} else {
			
			$result = $this->_gen();
			
		}


		return $result;
	}
}
